package com.ruoyi.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.domain.MesTasks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.mes.domain.MesPs;
import com.ruoyi.mes.service.IMesPsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产计划Controller
 * 
 * @author ruoyi
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/mes/ps")
public class MesPsController extends BaseController
{
    @Autowired
    private IMesPsService mesPsService;

    /**
     * 查询生产计划列表
     */
    @PreAuthorize(hasPermi = "mes:ps:list")
    @GetMapping("/list")
    public TableDataInfo list(MesPs mesPs)
    {
        startPage();
        List<MesPs> list = mesPsService.selectMesPsList(mesPs);
        return getDataTable(list);
    }

    /**
     * 导出生产计划列表
     */
    @PreAuthorize(hasPermi = "mes:ps:export")
    @Log(title = "生产计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesPs mesPs) throws IOException
    {
        List<MesPs> list = mesPsService.selectMesPsList(mesPs);
        ExcelUtil<MesPs> util = new ExcelUtil<MesPs>(MesPs.class);
        util.exportExcel(response, list, "生产计划数据");
    }

    /**
     * 获取生产计划详细信息
     */
    @PreAuthorize(hasPermi = "mes:ps:query")
    @GetMapping(value = "/{mesPsUuid}")
    public AjaxResult getInfo(@PathVariable("mesPsUuid") String mesPsUuid)
    {
        return AjaxResult.success(mesPsService.selectMesPsByMesPsUuid(mesPsUuid));
    }

    /**
     * 新增生产计划
     */
    @PreAuthorize(hasPermi = "mes:ps:add")
    @Log(title = "生产计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesPs mesPs)
    {
        int a = mesPsService.insertMesPs(mesPs);
        if(a==1){
            return toAjax(a);
        }else {
//            return new AjaxResult(1521,"审核未通过，无车间计划自动生成");
            return null;
        }

    }

    /**
     * 修改生产计划
     */
    @PreAuthorize(hasPermi = "mes:ps:edit")
    @Log(title = "生产计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesPs mesPs)
    {
        return toAjax(mesPsService.updateMesPs(mesPs));
    }

    /**
     * 删除生产计划
     */
    @PreAuthorize(hasPermi = "mes:ps:remove")
    @Log(title = "生产计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mesPsUuids}")
    public AjaxResult remove(@PathVariable String[] mesPsUuids)
    {
        return toAjax(mesPsService.deleteMesPsByMesPsUuids(mesPsUuids));
    }
}
